<?php
include_once "../header1.php";
?>
<script type="text/javascript">
function cleartbox()
{	
	document.getElementById("Sea_Tra").innerHTML="";
}
</script>
<script type="text/javascript">
function getHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function showHint(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("List").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("List").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","tra_names.php?q="+str,true);
xmlhttp.send();
}
function fill(val)
{ 
document.T_name.TraName.value=val;
document.getElementById("List").innerHTML="";
}
</script>
<script type="text/javascript">
function getRes(hin)
{
	var xmlhttp;    
if (hin=="")
  {
  document.getElementById("Sea_Tra").innerHTML='<font class="err"><img src="../images/alert.jpg" width="12" height="12"/> Please enter the Training name!</font>';
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("Sea_Tra").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","search.php?q="+hin,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
include_once ("../Login/databaseconnection.php");

if(!loggedin())
{
	require_once ("../index.php");
}
   
   else
   {
   $action=$_GET['action'];
   if($_GET['action']=="training")
   {
  $Training_Id=$_GET['t'];
}
 if($_GET['action']=="teacher")
   { 
$Training_Id=$_GET['t'];  
$Teacher_NIC=$_GET['tea'];   
}
 if($_GET['action']=="school")
   {  
   $Training_Id=$_GET['t'];
   $School_Id=$_GET['s'];    
   }
   if($action=="training")
   {
   $nics="";
 	   if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
    $get_teaSch=mysql_query("SELECT * FROM teacher WHERE School_Id='$Own_School_Id'");
  if($rowsesch=mysql_fetch_array($get_teaSch))
{
$T_N_No=$rowsesch['T_NIC_Number'];
$get_te=mysql_query("SELECT * FROM training_details WHERE Teacher_NIC='$T_N_No'");
  if($row_te=mysql_fetch_array($get_te))
{
if(empty($nics))
{
$nics=$T_N_No;
}
else
{
$nics=$nics.",".$T_N_No;
}
}
}
$nic=$explode(",",$nics);
if(count($nic)>0)
{
$que="SELECT * FROM training_details WHERE Training_Id='$Training_Id' AND Teacher_NIC in(";
for($j=0;$j<count($nic);$j++)
{
if($j<count($nic)-1)
{
$que=$que."'".$nic[$j]."',";
}
if($j==count($nic)-1)
{
$que=$que."'".$nic[$j]."'";
}
}
$que=$que.")";
$Exc_que=$que;
$result=mysql_query($que);
if(mysql_num_rows($result)==0)
   {
   $_SESSION['errornorow']="Very sorry there is no result or you are not allowed to search this!";
   }
}
else
   {
   $_SESSION['errornotallo']="Sorry you are not allowed view this!";
   }
}
}
else if($_SESSION['Access_Type']=="Administrator")
{
$Exc_que="SELECT * FROM training_details WHERE Training_Id='$Training_Id'";
$result=mysql_query("SELECT * FROM training_details WHERE Training_Id='$Training_Id'");
if(mysql_num_rows($result)==0)
   {
$_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
   }
   }
   else
   {
   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
   }
 }
  if($action=="teacher")
   {
 	   if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
    $get_teaSch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$Teacher_NIC'");
  if($rowsesch=mysql_fetch_array($get_teaSch))
{
$schid=$rowsesch['School_Id'];
if($schid==$Own_School_Id)
{
$Exc_que="SELECT * FROM training_details WHERE Training_Id='$Training_Id' AND Teacher_NIC='$Teacher_NIC'";
$result=mysql_query("SELECT * FROM training_details WHERE Training_Id='$Training_Id' AND Teacher_NIC='$Teacher_NIC'");
if(mysql_num_rows($result)==0)
   {
   $_SESSION['errornorow']="Very sorry there is no result or you are not allowed to search this!";
   }
}
else
   {
   $_SESSION['errornotallo']="Sorry you are not allowed view this!";
   }
}
}
}
else if($_SESSION['Access_Type']=="Administrator")
{
$Exc_que="SELECT * FROM training_details WHERE Training_Id='$Training_Id' AND Teacher_NIC='$Teacher_NIC'";
$result=mysql_query("SELECT * FROM training_details WHERE Training_Id='$Training_Id' AND Teacher_NIC='$Teacher_NIC'");
if(mysql_num_rows($result)==0)
   {
$_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
   }
   }
   else
   {
   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
   }
 }
  if($action=="school")
   {
 	   if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
if($School_Id==$Own_School_Id)
{
$Exc_que="SELECT * FROM training_details WHERE Training_Id='$Training_Id' AND School_Id='$School_Id'";
$result=mysql_query("SELECT * FROM training_details WHERE Training_Id='$Training_Id' AND School_Id='$School_Id'");
if(mysql_num_rows($result)==0)
   {
   $_SESSION['errornorow']="Very sorry there is no result or you are not allowed to search this!";
   }
}
else
   {
   $_SESSION['errornotallo']="Sorry you are not allowed view this!";
   }

}
}
else if($_SESSION['Access_Type']=="Administrator")
{
$schs="";
$get_teaSchoo=mysql_query("SELECT * FROM teacher WHERE School_Id='$School_Id'");
  while($rowseschoo=mysql_fetch_array($get_teaSchoo))
{
$T_N_No=$rowseschoo['T_NIC_Number'];
$get_te_schoo=mysql_query("SELECT * FROM training_details WHERE Teacher_NIC='$T_N_No'");
  if($row_te_schoo=mysql_fetch_array($get_te_schoo))
{
if(empty($schs))
{
$schs=$T_N_No;
}
else
{
$schs=$schs.",".$T_N_No;
}
}
}
$scs=explode(",",$schs);
$que="SELECT * FROM training_details WHERE Training_Id='$Training_Id' AND Teacher_NIC in(";
for($j=0;$j<count($scs);$j++)
{
if($j<count($scs)-1)
{
$que=$que."'".$scs[$j]."',";
}
if($j==count($scs)-1)
{
$que=$que."'".$scs[$j]."'";
}
}
$que=$que.")";
$Exc_que=$que;
$result=mysql_query($que);
if(mysql_num_rows($result)==0)
   {
$_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
   }
   }
   else
   {
   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
   }
 }
?>
   
<?php
include_once "../header2.php";
?>
<?php
include_once "topmenu.php";
?>
<div id="content">
	<div id="main">
	  <div id="bodyfield">
<div id="lefttable">
<table width="530" border="0" class="tablefontv">
<tr><td width="47" height="43" class="err">
<?php
if(isset($_SESSION['errornotallo']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornotallo'];
		unset($_SESSION['errornotallo']);
	}
	if(isset($_SESSION['errornorow']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornorow'];
		unset($_SESSION['errornorow']);
	}
?>
</td></tr></table>
 <table width="530" border="0" class="tablefontv">
  <tr><form name="T_name">
  <td width="47" height="43"></td>
      <td width="131">Training Name:</td>
      <td width="149">
	  <?php
	  $tnam=mysql_query("SELECT * FROM training WHERE Training_Id='$Training_Id'");
	  if($rot=mysql_fetch_array($tnam))
	  {
	  $Trai_name=$rot['Training_Name'];
	  }
	  echo "<input type='text' id='TraName' name='TraName' onKeyUp='showHint(this.value)' value='$Trai_name' onClick='cleartbox()'/>";
	  ?>
	  </td>
      <td width="33"><input type="button" class="searchid" onClick="getRes(TraName.value)"></td>
      <td width="148">
     </td></form>
  </tr>
  <tr>
  <td>
  </td>
  <td>
  </td><td>
 <div class="suggestionListPro" id="List"></div> </td>
 <td>
 </td>
 <td></td>
  </tr></table>
   <br/>
   <div id="Sea_Tra"> 
   <?php
   if($result)
	   {
	   if(mysql_num_rows($result)>1)
	   {
	   $colu="";
	   $sql=mysql_query("SHOW COLUMNS FROM training_details");
if(mysql_num_rows($result)>11)
{
echo '<div style="width:700px; height:400px; overflow-Y:scroll; ">';
}
      echo '<table border="1" class="tablefontv">';
	  echo "<tr bgcolor='#6AB5FF'>";
	while($rowc=mysql_fetch_row($sql))
  {
  if(empty($colu))
  {
  $colu=$rowc[0];
  }
  else
  {
   $colu=$colu.",".$rowc[0];
  }
  if($rowc[0]=="Training_Id")
  {
  echo "<td>Training Name</td>";
  }
  else
  {
  echo "<td>".str_replace("_"," ",$rowc[0])."</td>";
  }
  }
  echo "</tr>";
 $columns=explode(",",$colu);
        while($row=mysql_fetch_array($result))
  {
 echo "<tr bgcolor='#999999'>";
  for($cv=0;$cv<mysql_num_rows($sql);$cv++)
	{
	 $col_name=$columns[$cv];
	  if($col_name=="Training_Id")
  {
  $res=mysql_query("SELECT * FROM  training WHERE Training_Id='".$row[$col_name]."'");
if($rowc=mysql_fetch_array($res))
{
$Training_Name=$rowc['Training_Name'];
}
  echo "<td>".$Training_Name."</td>";
  }
  else
  {
  echo "<td>".$row[$col_name]."</td>";
  }	  
	}
	  echo '</tr>';
	}
	echo '</table>';
if(mysql_num_rows($result)>11)
{
echo '</div>';
}
	   }
	   if(mysql_num_rows($result)==1)
	   {
echo '<table width="458" border="0" class="tablefontv">';
 while($row=mysql_fetch_array($result))
  {
$Training_Id=$row['Training_Id'];
$res=mysql_query("SELECT * FROM  training WHERE Training_Id='$Training_Id'");
if($rowc=mysql_fetch_array($res))
{
$Training_Name=$rowc['Training_Name'];
}
	 $s_name=$row['Training_Id'];
$Teacher_NIC =$row['Teacher_NIC'];
$No_Of_Sat =$row['Duration'];
 
     
      echo '<tr>';
        echo '<td width="200" height="44" scope="row" bgcolor="#0054A8">';
		echo "Training Id:";
		echo '</td>';
        echo '<td width="144" bgcolor="#6AB5FF">';
		echo $s_name;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<td height="44" scope="row" bgcolor="#0054A8">';
		echo "Teacher NIC:";
		echo '</td>';
        echo '<td bgcolor="#6AB5FF">';
		echo $Teacher_NIC;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<td height="44" scope="row" bgcolor="#0054A8">';
		echo "Training Name :";
		echo '</td>';
        echo '<td bgcolor="#6AB5FF">';
		echo $rowc['Training_Name'];
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<td height="44" scope="row" bgcolor="#0054A8">';
		echo "Duration:"; 
		echo '</td>';
       echo '<td bgcolor="#6AB5FF">';
	  echo $No_Of_Sat;
	   echo '</td>';
      echo '</tr>';
	}
    echo '</table>';
	}
	}
	if($result)
{
$Exc_quer=str_replace("'","@",$Exc_que);
echo "<form action='../exportreport.php' method='post'><input type='submit' name='ToExcel' class='print' value=''/><input type='hidden' value='$Exc_quer' name='query'/><input type='hidden' value='training_details' name='Exc_table_name'/></form>";
}
	   ?>
</div>
</div>
</div>
</div>
</div>
<div id="sidebar">
<br/>
<div id="partners" class="boxed">
			<h2 class="title">TRAINING DETAILS</h2>
            </div> 
<?php
include_once "menu.php";
?>
<?php
include_once "../footer.php";
?>
<?php
}
?>
</body>
</html>